<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<head th:include="include :: header">
</head>
<link rel="stylesheet" th:href="@{/css/yw.css}">

<body class="hold-transition skin-blue sidebar-mini">
<style>
    .table-border tbody tr td{
        border-top: 1px solid black;
    }
</style>
<section class="content-header">
    <h1>
        项目款票列表
    </h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group" style="margin-right: 10px;">
                                    <label>项目编号 </label>
                                    <input id="contName" name="contName" class="form-control" placeholder="请输入项目编号"
                                           type="text">
                                </div>
                                <!--<div class="form-group" style="margin-right: 10px;">-->
                                <!--<label>买家合同编号</label>-->
                                <!--<input type="text" name="buyCode" class="form-control" placeholder="请输入买家合同编号">-->
                                <!--</div>-->
                                <div class="form-group" style="margin-right: 10px;">
                                    <label>卖方合同编号</label>
                                    <input type="text" name="sellCode" class="form-control" placeholder="请输入卖方合同编号">
                                </div>
                                <div class="form-group" style="margin-right: 10px;">
                                    <label>签订日期</label>
                                    <input type="text" class="form-control datepicker" name="beginTime"
                                           placeholder="开始日期" readonly>
                                    至
                                    <input type="text" class="form-control datepicker" name="endTime"
                                           placeholder="结束日期" readonly>

                                </div>

                                <div class="form-group" style="margin-right: 10px;">
                                    <label>类别</label>
                                    <select class="form-control" style="margin-right: 10px;" id="leibieEdit"
                                            name="contType">
                                        <option value="" selected="selected">请选择</option>
                                        <option value="对内销售">对内销售</option>
                                        <option value="对内采购">对内采购</option>
                                        <option value="合作制造">合作制造</option>
                                    </select>
                                </div>
                                <div class="form-group" style="margin-right: 10px;">
                                    <label style="margin-right: 10px;">回款类型</label>
                                    <select class="form-control" style="margin-right: 10px;" id="huikuanType"
                                            name="returnType">
                                        <option value="" selected="selected">请选择</option>
                                        <option value="已回全">已回全</option>
                                        <option value="未回全">未回全</option>
                                        <option value="有抹账">有抹账</option>
                                        <option value="有坏账">有坏账</option>
                                    </select>
                                </div>
                                <div class="form-group" style="margin-right: 10px;">
                                    <label>款票状态</label>
                                    <select class="form-control" style="margin-right: 10px;"
                                            id="kuanpiaozhuangtaiEdit" name="moneyInvoiceStatue">
                                        <option value="">请选择</option>
                                        <option value="0" selected="selected">未完成</option>
                                        <option value="1">保存未提交</option>
                                        <option value="2">提交未审核</option>
                                        <option value="3">被驳回</option>
                                        <option value="4">已完结</option>
                                    </select>
                                </div>


                                <button type="button" class="btn btn-success" id="btn-search"
                                        style="margin-top: 5px;">
                                    <!--<i class="fa fa-search"></i>-->
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <!--<table  id="bootstrap-table" style="table-layout: fixed;word-break:break-all; word-wrap:break-word;"></table>-->
                    <table class="table-border" id="bootstrap-table" ></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer">
</div>

<script th:inline="javascript">
    /**
     * 表格搜索
     */
    $("#btn-search").click(function () {
        js.table.search(table);
    });


    //
    <!-- 百度搜索  input模糊查询有备选项下拉框-->
    // <!--<label>项目编号test </label>-->
    // <!--<input id="contName" name="contName" class="form-control" placeholder="请输入项目编号"
    // <!--type="text"  list="contName_list"  autocomplete="off">
    // <datalist id="contName_list">
    // </datalist>
    //   $('#contName').bind('keyup', function () {
    //   var contName = $('#contName').val();
    //   $.ajax({
    //         url: ctx + "inputTest",
    //         type: "GET",
    //         dataType: 'json',
    //         data: {'contName': contName},
    //         async: false,
    //         success: function (arg) {
    //             $('#contName_list').empty();
    //             for (var i = 0; i < arg.length; i++) {
    //                   var add_options = '<option value="' + arg[i] + '">'+ arg[i] + '</option>';
    //                   $('#contName_list').append(add_options);
    //             }
    //         }
    //     })
    // });


    //
    <!-- 输入整数 整保留两位小数 且 最多只能输入两位小数-->
    //     <input id="num2" name="num2" class="form-control" placeholder="请输入项目编号"
    // type="number" step="0.01"  min="0" onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''" >

    // $("#num2").blur(function () {
    //     debugger;
    //     var a = /^[1-9]\d*$/; //整数
    //     var b = /^(\d+)(\.\d{1})?$/; //一位小数
    //     if (a.test($(this).val())) {
    //         $(this).val(ChangeNumValue2($(this).val()));
    //     }
    //     if (b.test($(this).val())) {
    //         $(this).val(ChangeNumValue3($(this).val()));
    //     }
    // });
    // function ChangeNumValue2(tmpVal) {
    //     tmpVal = tmpVal + ".00";
    //     return tmpVal;
    // }
    // function ChangeNumValue3(tmpVal) {
    //     tmpVal = tmpVal + "0";
    //     return tmpVal;
    // }
    // $("#contName").keyup(function () {
    //     $(this).val(ChangeNumValue1($(this).val()));
    // });
    // function ChangeNumValue1(tmpVal) {
    //     if (tmpVal) {
    //         var tmpVal = tmpVal.replace(/[^\d\.]/g, '');
    //         var reg = /^(0|([1-9]\d*))(\.\d{1,2})?$/; //正则验证保留 最多允许后输入两位小数
    //         if (!reg.test(tmpVal)) {
    //             tmpVal = tmpVal + "";
    //             tmpVal = tmpVal.substring(0, tmpVal.indexOf(".") + 3);
    //             var n = (tmpVal.split('.')).length - 1;
    //             if (n > 1) {
    //                 tmpVal = tmpVal.substring(0, tmpVal.indexOf("."));
    //             }
    //         }
    //         return tmpVal;
    //     }
    // }


    $(function () {
        /** 加载用户表格 */
        table = js.table.init({
            url: ctx + "InvoiceList",
            showColumns: true,
            showExport: true,
            pageSize: 2,
            pagination: false,
            columns: [
                {
                    title: '序号', field: 'id', width: '50',
                    formatter: function (value, row, index, field) {
                        var pageSize = table.bootstrapTable('getOptions').pageSize;
                        var pageNumber = table.bootstrapTable('getOptions').pageNumber;
                        return pageSize * (pageNumber - 1) + index + 1;
                    }
                },
                {
                    title: "项目编号", field: 'contName',
                    formatter: function (value, row, index) {
                        return changeRow(value)
                    }
                },
                {title: "类别", field: 'contType'},
                {title: "买方", field: 'totalMethod'},
                {title: "业主方", field: 'contPartner'},
                {title: "卖方<br>合同号", field: 'sellCode'},
                {
                    title: "签订日期", field: 'contYear',
                    formatter: function (value, row, index) {
                        return changeDateFormat(value)
                    }
                },
                {title: "数量", field: 'cnt'},
                {
                    title: "分包已<br>收金额", field: 'sumAlreadyMoney'
                    , formatter: function (value, row, index) {
                        return isZero(value, row);
                    }
                },
                {
                    title: "分包收<br>款比例", field: 'collectionScale',
                    formatter: function (value, row, index) {
                        return changeHundred(value, row);
                    }
                },
                {
                    title: "分包已<br>开发票", field: 'sumAlreadyInvoiceAmount'
                    , formatter: function (value, row, index) {
                        return isZero(value, row);
                    }
                },
                {
                    title: "分包开<br>票比例", field: 'invoiceScale',
                    formatter: function (value, row, index) {
                        return changeHundred(value, row);
                    }
                },
                {
                    title: "应收未收", field: 'conYsws'
                    , formatter: function (value, row, index) {
                        return isZero(value, row);
                    }
                },
                {
                    title: "抹账金额", field: 'rmiDebtsMoney',
                    formatter: function (value, row, index) {
                        return isZero(value, row);
                    }
                },
                {
                    title: "坏账金额", field: 'rmiBadMoney',
                    formatter: function (value, row, index) {
                        return isZero(value, row);
                    }
                },
                {
                    title: "款票状态", field: 'moneyInvoiceStatue', formatter: function (value, row, index) {
                        if (value === 0) {
                            return '<span class="label  badge  label-default">未完成</span>';
                        } else if (value === 1) {
                            return '<span class="label  badge  label-warning">保存未提交</span>';
                        } else if (value === 2) {
                            return '<span class="label  badge  label-primary">提交未审核</span>';
                        } else if (value === 3) {
                            return '<span class="label  badge  label-danger">被驳回</span>';
                        } else if (value === 4) {
                            return '<span class="label  badge  label-success">已完结</span>';
                        }
                    }
                },
                {
                    title: "操作", formatter: function (value, row, index) {
                        var actions = [];
                        if (hasP("pay:infor:view")) {
                            if (row.moneyInvoiceStatue === 0 || row.moneyInvoiceStatue === 1 || row.moneyInvoiceStatue === 3) {
                                actions.push('<a class="btn btn-warning btn-xs" href="' + ctx + 'kpEdit/contractInfo?conId=' + row.conId + '" > 编辑</a> ');
                            }
                        }
                        actions.push('<a class="btn btn-success btn-xs" target="_blank" href="' + ctx + 'kpSelect/contractInfo?conId=' + row.conId + '" > 查看</a> ');
                        return actions.join('');
                    }
                }

            ],

        });

    })

    /**
     * 百分比转换  保留4位小数
     * @param value
     * @returns {string}
     */
    function changeHundred(value) {
        if (value == null || value == undefined || value === "" || value == "null" || value == 'undefined') {
            return 0 + '%';
        }
        var str = Number(value * 100).toFixed(2);
        str += "%";
        return str;
    }


    function isZero(value) {
        if (value == null || value == undefined || value === "" || value == "null" || value == 'undefined') {
            return '0';
        } else if (value == 0 || value == '0') {
            return value;
        }
        else {
            return value;
        }
    }


    /**
     * 日期格式转换
     * @param value
     * @returns {*}
     */
    function changeDateFormat(value) {
        if (value == '' || value == undefined) {
            return "";
        }
        var myDate = new Date(value);
        //获取当前年
        var year = myDate.getFullYear();
        //获取当前月
        var month = myDate.getMonth() + 1;
        month = month < 10 ? "0" + month : month;
        //获取当前日
        var date = myDate.getDate();
        date = date < 10 ? "0" + date : date;
        var h = myDate.getHours();       //获取当前小时数(0-23)
        h = h < 10 ? "0" + h : h;
        var m = myDate.getMinutes();     //获取当前分钟数(0-59)
        m = m < 10 ? "0" + m : m;
        var s = myDate.getSeconds();
        s = s < 10 ? "0" + s : s;
        var time = year + '-' + month + "-" + date;
        return time;
    }

    function changeRow(value) {
        var code = value;
        var code2 = code.replace(/;/g, "<br>");
        return code2.replace(/；/g, "<br>");
    }

</script>